<template>
	<view class="content">
		<!-- <view class="startimg"> -->
			<image class="startimg" :src="imgurl+'startimg.png'" mode=""></image>
		<!-- </view> -->
		<view class="content_box">
			<button class="login_btn" v-if="ischange" @click="getuserinfo">
				微信账号一键登录
			</button>
			<button class="login_btn" v-else>
				微信账号一键登录
			</button>
			<view class="phonechecked">
				<checkbox-group @change="checkboxChange">
				<checkbox value="cb" :checked="ischecked" color="#fff" style="transform:scale(0.7)"
					class="round red" />我已阅读并同意<text class="xieyi" @click="onyonghu">《用户协议》</text>和<text class="xieyi" @click="onyinsi">《隐私政策》</text>
				</checkbox-group>
			</view>
		</view>
		
	</view>
</template>

<script>
	import {login} from '../../../utils/app.js'
	export default{
		data(){
			return {
				imgurl: getApp().globalData.imgurl,
				ischecked:false,
				ischange:false
			}
		},
		methods:{

			// 跳转到用户协议
			onyonghu(){
				uni.navigateTo({
					url:'/pages/subPack/UserAgreement/UserAgreement'
				})
			},
			// 跳转到隐私政策
			onyinsi(){
				uni.navigateTo({
					url:'/pages/subPack/PrivacyPolicy/PrivacyPolicy'
				})
			},
			
			
			// 点击登录
			getuserinfo(){
				console.log('000');
				      uni.getUserProfile({
				        desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
				        success: (res) => {
				          console.log(res)
				          this.getopenId(res)
				          // this.setData({
				          //   userInfo: res.userInfo,
				          //   hasUserInfo: true
				          // })
				        },
						complete:(res)=>{
							console.log('111');
							console.log(res);
						}
				      })
					  console.log('222');
			},
			getopenId(data){
				uni.login({
					success: (res) => {
						login({
							code: res.code,
							nickname: data.userInfo.nickName,
							avatar: data.userInfo.avatarUrl
						}).then(res => {
							console.log(res);
							if(res.code==1){
								uni.setStorageSync('token',res.data.api_token)
								var pages = getCurrentPages();
								var prevPage = pages[pages.length - 2]; //上一个页面
								console.log(prevPage);
								// prevPage.setData({
								//      cityobj: e
								//    })
								   prevPage.onLoad()
								   // console.log(prevPage.$vm);
								   // prevPage.$vm.getList()
								   uni.navigateBack({//返回
								     delta: 1,
									 // success() {
										//  console.log(prevPage.$vm);
									 // 	prevPage.$vm.getList()
									 // }
								   })
							} else {
								uni.showToast({
									title:'登录失败',
									icon:'none'
								})
								uni.navigateBack({delta:1})
							}
						
							
							// this.SystemCateList = res.data
							// this.getSystemBanner(this.active)
							// this.getHomeData(true)
							// this.dataList = res.data
						
						})
					}
				})
			},
			
			checkboxChange(e){
				console.log(e.detail.value.length>0);
				if(e.detail.value.length>0){
					this.ischange = true
				} else {
					this.ischange = false
				}
			},
		}
	}
</script>

<style>
	.content{
		width: 100%;
		height: 100vh;
		background: url(https://yuanchubao.oss-cn-beijing.aliyuncs.com/loginbjimg.png) no-repeat;
		background-size: 100% 100%;
		
	}
/* 	.content{
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		position: relative;
	} */
	.startimg{
		width: 464rpx;
		height: 197rpx;
		/* margin-top: 480rpx; */
		position: absolute;
		left: 50%;
		top: 35%;
		transform: translate(-50%,-50%);
	}
	.content_box{
		/* margin-top: 470rpx; */
		position: absolute;
		left: 50%;
		bottom: 16%;
		transform: translateX(-50%);
	}
	.login_btn{
		width: 650rpx;
		height: 88rpx;
		background: #FFFFFF;
		border-radius: 44rpx;
		font-size: 28rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #EE0E6B;
		line-height: 88rpx;
		text-align: center;
		
	}
	.phonechecked {
		font-size: 22rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #fff;
		/* line-height: 15rpx; */
		display: flex;
		align-items: center;
		margin-left: 60rpx;
		margin-top: 16rpx;
	}
	.xieyi{
		color: #00A0E9;
	}
	
	/*每个页面公共css */
	/* //设置圆角 */
	checkbox.round .wx-checkbox-input,
	checkbox.round .uni-checkbox-input {
		border-radius: 100rpx;
		border: 2rpx solid #FF0000;
	}
	
	/* //设置背景色 */
	checkbox.red[checked] .wx-checkbox-input,
	checkbox.red.checked .uni-checkbox-input {
		background-color: #ffffff !important;
		border-color: #FF0000 !important;
		color: #FF0000 !important;
	}
	
	uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked:before {
		content: '\2022';
	}
</style>